package com.gao.cluster.controller;

import com.gao.cluster.common.Constants;
import com.gao.cluster.common.res.ProductResult;
import com.gao.cluster.po.Product;
import com.gao.cluster.vo.ProductVo;
import com.gao.cluster.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ProductController {

    @Autowired
    private ProductService productService;

    /**
     * 查询产品信息
     * @return
     */
    @GetMapping("queryProd")
    public ProductResult queryProductInfo(@RequestParam("id") Long id) {
        Product product = productService.queryProductInfo(id);
        ProductResult productResult = new ProductResult(Constants.ResponseCode.SUCCESS.getCode(), Constants.ResponseCode.SUCCESS.getInfo());
        ProductVo productVo = new ProductVo();
        productVo.setProductId(product.getProductId());
        productVo.setProductName(product.getProductName());
        productVo.setProductType(product.getProductType());
        productVo.setStockSurplusCount(product.getStockSurplusCount());
        productResult.setProductVo(productVo);

        return productResult;
    }
}
